const API = require('../../utils/api');
Page({

  data: {
    books:[],
    isNull: true
  },

  onLoad(options) {
    
  },
  onShow: function () {
    this.updata()
  },
  updata: function(e){
    var id = wx.getStorageSync('id');
    console.log(id)
    API.getbookshelf({
      "id":id
    }).then(resp=>{
      if(resp == ''){
        this.setData({
          books:resp,
          isNull:true
        })
        wx.lin.renderWaterFlow(this.data.books, true ,()=>{
          console.log('渲染成功')
        })
      }else{
        for(let i = 0;i<resp.length;i++){
          resp[i].book.bookDesc =resp[i].book.bookDesc.replace(/<br\/><br\/>/g,'\n')
        }
        if(this.data.books.toString() != resp.toString()){
          this.setData({
            books:resp,
            isNull:false
          })
          wx.lin.renderWaterFlow(this.data.books, true ,()=>{
            console.log('渲染成功')
          })
        }
      }
        
    })
  },
  deleteBook(){
    setTimeout(() => {
      this.updata();
    }, 100)
   
  }
})  